Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing Extensions and Drivers /
Chapter 3 - Printer Drivers / The QuickDraw GX ImageWriter II Printer Driver Messages


Storing the Current Printer Configuration

QuickDraw GX sends the GXOpenConnection message to open a connection with a printing device. You can override this message, which is described on page 4-131 in the chapter "Printing Messages," to perform any special operations that you need to do at the time of connection.

The ImageWriter II printer driver overrides the GXOpenConnection message to update the printer configuration that is stored with the desktop printer. It first sends a query to the printing device for its hardware configuration, which includes information about the sheet-feeder and color-ribbon options. It then stores that information with the desktop printer. This message override, the SD_OpenConnection function, is shown in
Listing 3-8.

Listing 3-8 Opening the connection with the printing device

OSErr SD_OpenConnection(void)
{
   OSErr    anErr;
   
   /* first, open the connection the standard way */
   anErr = Forward_GXOpenConnection();
   nrequire(anErr, OpenConnection);
   
   /*
      then, bring the desktop-printer configuration information
      up to date
   */
   anErr = UpdateConfiguration();
   nrequire(anErr, UpdateConfiguration);
      
   return(noErr);

/* exception handling */
UpdateConfiguration:
   GXCleanupOpenConnection();
OpenConnection:

   return(anErr);
} 
The SD_OpenConnection function queries and stores the hardware configuration by calling a local function, UpdateConfiguration. This function, which is shown in Listing 3-9, calls the FetchStatusString function to query the ImageWriter II and then stores the information in the printer configuration file.

Listing 3-9 Getting information about the configuration of the printing device

OSErr UpdateConfiguration(void)
{
   Str32                      deviceName;
   OSErr                      anErr = noErr;
   ImageWriterConfigHandle    configHandle;
   ImageWriterConfigPtr       configPtr;
   Boolean                    isImageWriterII = false;
   ResType                    commType;
   
      
   /* find out printer name and how the printer is connected */
   GXGetPrinterName(GXGetJobOutputPrinter(GXGetJob()),
                                                   deviceName);
   anErr = GXFetchDTPData(deviceName, gxDeviceCommunicationsType,
               gxDeviceCommunicationsID, (Handle*)&configHandle);
   nrequire(anErr, FetchCommType);
   commType = **(ResType**)configHandle;
   DisposHandle((Handle) configHandle);
   
   /* store the communications type for future use */
   {
   SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext();
   
   (**hGlobals).commType = commType;
   }
   
   /* find out the original configuration */
   if (GXFetchDTPData(deviceName, kImageWriterConfigType,
         kImageWriterConfigID, (Handle*)&configHandle) == noErr)
      {
      /* remember that it was an IW2 */
      configPtr = *configHandle;
      isImageWriterII = configPtr->isImageWriterII;
      DisposeHandle((Handle) configHandle);

      /*
         If this is not an ImageWriter II, bail out now
         because the timeout takes two minutes!
      */
      if (!isImageWriterII)
         return(noErr);
      }
   else
      {     
      
      /* if not sure yet, assume IW2 for PAP and IW1 otherwise */
      if (commType == 'PPTL')
         isImageWriterII = true;
      }
      
   /* make a handle to hold configuration info for the printer */
   configHandle = (ImageWriterConfigHandle)
                     NewHandle(sizeof(ImageWriterConfigRecord) );
   anErr = MemError();
   nrequire(anErr, NewHandle);
   
   /* set up the default for the device */
   configPtr = *configHandle;
   configPtr->hasColorRibbon = false;
   configPtr->hasSheetFeeder = false;
   configPtr->isImageWriterII = true;
   
   {
   short    statusReturn;
   
   /* query the device */
   anErr = FetchStatusString(&statusReturn, (commType == 'PPTL'));
   
   /*
      Scan the status string looking for information about
      printer kind and options.
   */
   configPtr = *configHandle;
   if ( anErr == gxAioTimeout )
      {
      /*
         If you don't know what kind of printer it is and the
         request timed out, assume that it is an IW1.
      */
      if (!isImageWriterII)
         {
         anErr = noErr;
         configPtr->isImageWriterII = false;
         }
      }
   else
      {
      configPtr->hasColorRibbon =
               (statusReturn & (0x1000 >> kColorRibbonBit)) != 0;
      configPtr->hasSheetFeeder =
               (statusReturn & (0x1000 >> kSheetFeederBit)) != 0;
      }
   nrequire(anErr, FetchStatusString);
   }
   
   /* write out the new configuration */
   anErr = GXWriteDTPData(deviceName, kImageWriterConfigType,
                     kImageWriterConfigID, (Handle)configHandle);
   
   
/* exception handling */
FetchStatusString:
   DisposHandle((Handle) configHandle);
   
NewHandle:
FetchCommType:
   return(anErr);
   
}
The UpdateConfiguration function first calls the GXFetchDTPData function to access the communications type that is stored for the printer with the desktop printer. UpdateConfiguration next calls GXFetchDTPData to determine with which kind of printer it is communicating. Then, UpdateConfiguration calls the FetchStatusString function. This is a local function that sends a query to the hardware device and receives a status string back from it. UpdateConfiguration examines the status string to determine whether the printer has a sheet feeder or a color ribbon. Finally, UpdateConfiguration calls the GXWriteDTPData function to store the information that it has updated in the desktop printer.

Desktop printers are described in Inside Macintosh: QuickDraw GX Printing. The GXFetchDTPData function is described on page 5-27 and the GXWriteDTPData function is described on page 5-26 in the chapter "Printing Functions for Message Overrides."


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help